package com.bajiao.service.message.impl;

import com.bajiao.common.constant._Whole;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bajiao.entity.message.Message;
import com.bajiao.mapper.message.MessageMapper;
import com.bajiao.service.message.MessageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 消息表
 * @Author: FanJq
 * @Date: 2024-10-10
 * @Version: V1.0
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements MessageService {

    /**
     * @Description
     * 最新公告列表
     * @date 2024/12/12 15:21
     * @author FanJq
     * @param limit
     * @return {@link List< Message>}
    */
    @Override
    public List<Message> getLatest(Integer limit) {
        List<Message> messageList = super.lambdaQuery()
                .eq(Message::getDelFlag, _Whole.ZERO)
                .orderByDesc(Message::getCreateTime)
                .last("LIMIT " + limit).list();
        return messageList;
    }

    /**
     * @Description
     * 公告详情
     * @date 2024/12/12 15:22
     * @author FanJq
     * @param messageId
     * @return {@link Message}
    */
    @Override
    public Message getDetails(String messageId) {
        Message message = super.getById(messageId);
        super.lambdaUpdate()
                .setSql("browse = browse + 1")
                .eq(Message::getId, messageId)
                .update();
        return message;
    }

    /**
     * @Description
     * 公告列表
     * @date 2024/12/12 15:22
     * @author FanJq
     * @param
     * @return {@link List< Message>}
    */
    @Override
    public List<Message> getList() {
        List<Message> messageList = super.lambdaQuery()
                .eq(Message::getDelFlag, _Whole.ZERO)
                .orderByDesc(Message::getCreateTime)
                .list();
        return messageList;
    }
}
